package org.javaboy.vhr.service.impl;

import org.javaboy.vhr.mapper.ResignMapper;
import org.javaboy.vhr.model.Resign;
import org.javaboy.vhr.model.RespPageBean;
import org.javaboy.vhr.service.ResignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ResignServiceImpl implements ResignService {
    @Autowired
    ResignMapper resignMapper;

    @Override
    public RespPageBean getAllResigns(Integer page, Integer size, String keywords) {
        if (page != null && size != null) {
            page = (page - 1) * size;
        }
        List<Resign> data = resignMapper.getAllResigns(page, size, keywords);
        Long total = resignMapper.getTotal(keywords);
        RespPageBean respPageBean = new RespPageBean();
        respPageBean.setData(data);
        respPageBean.setTotal(total);
        return respPageBean;
    }

    @Override
    public Resign getResignById(Integer id) {
        return resignMapper.getResignById(id);
    }

    @Override
    @Transactional
    public boolean updateResignStatus(Resign resign) {
        return resignMapper.updateResignStatus(resign) == 1;
    }

    @Override
    @Transactional
    public boolean addResign(Resign resign) {
        return resignMapper.addResign(resign) == 1;
    }

    @Override
    @Transactional
    public boolean deleteResign(Integer id) {
        return resignMapper.deleteResign(id) == 1;
    }
}
